package analyse;

import java.math.BigDecimal;
import java.util.List;

import data.Constant;

public class DealAmountAlyz extends AbstractAlyzer{

	public DealAmountAlyz() {
	}

	@Override
	DealDayData alanalyze(List<DealDayData> dealDatas) {
		BigDecimal allAmount = Constant.ZERO;
		List<DealDayData> tds;
		if(dealDatas.size()<20){
			tds = dealDatas;
		}else{
			tds = dealDatas.subList(0, 20);
		}
		for (DealDayData dealDayData : tds) {
			allAmount=allAmount.add(dealDayData.getAmount());
		}
		BigDecimal averAmount = allAmount.divide(new BigDecimal(tds.size()),0,BigDecimal.ROUND_HALF_UP);
		DealDayData ddd = dealDatas.get(0);
		ddd.setAmountBat(ddd.getAmount().divide(averAmount,2,BigDecimal.ROUND_HALF_UP));
		ddd.setAverAmount(averAmount);
		
		for(DealDayData dealDayData : tds) {
			if(dealDayData.getAmountBat()!=null&&dealDayData.getAmountBat().compareTo(new BigDecimal("2.4"))>0){
				ddd.setAmtCreDays(dealDayData.getSeq());
			}
		}
		return ddd;
	}
}
